﻿--[[
   @brief    banner control for wegame banner
   @author   harleyxwang
   @version  1.0
   @date     2017-04-21
--]]

ierd_tgp.tpf_ui.Require("event_ids.lua");

banner_control =
{
    need_repair = 1;
    all_channel = 2;
    check_repair_cfg_data = nil;
    color_text_ = "COLOR:RGB:48,48,51;";
    frame_url = LoadStr("WEGAME_FRAME_INDEX_URL");
    const_frame_url_str = nil;
    frame_url_holder = nil;
    jump_module_web_json = "";
    rejump_number = 0;
    init = function()
        banner_control.inner_log("init");
        banner_control.const_frame_url_str, banner_control.frame_url_holder = U8toCUIStr(banner_control.frame_url);
        ierd_tgp.tpf_ui.Require("wegame_banner\\model.lua");
        ierd_tgp.tpf_ui.Require("wegame_banner\\view.lua");
        ierd_tgp.tpf_ui.Require("wegame_banner\\gametipsmgr.lua");
        local tpfui =
            base_utility.get_component_adapter("ITpf_ui",
                "ierd_tgp.tpf_ui.GetTPFUI();");

        tpfui:AddLuaListener(ierd_tgp.game_library.UPDATE_VISIBLE_GAME_LIST, "banner_control.update_visible_game_list");
        tpfui:AddLuaListener(ierd_tgp.game_library.UPDATE_ALL_GAME_BASE_INFO, "banner_control.update_all_game_base_info");
        tpfui:AddLuaListener(ierd_tgp.game_library.UPDATE_GAME_SERVERS, "banner_control.update_game_servers");
        tpfui:AddLuaListener(ierd_tgp.game_library.UPDATE_GAME_STATE, "banner_control.update_game_state");
        tpfui:AddLuaListener(ierd_tgp.game_library.UPDATE_PLUGIN_STATE, "banner_control.update_plugin_state");
        tpfui:AddLuaListener(ierd_tgp.game_library.JSON_CFG_UPDATED, "banner_control.on_get_json_cfg");
        tpfui:AddLuaListener(ierd_tgp.game_library.K_PREUPDATE_PROCESS, "banner_control.update_predownload_state");
        tpfui:AddLuaListener(ierd_tgp.game_library.K_PREUPDATE_RESULT, "banner_control.update_predownload_state");

        tpfui:AddLuaListener(ierd_tgp.game_library.K_SEND_VIEWED_GAME_TIPS, "GameTipsMgr.update_viewed_game_tips");
        tpfui:AddLuaListener(ierd_tgp.game_library.GET_MY_GAME_LIST_FINISHED, "banner_view.notify_game_list_ready");
        tpfui:AddInterval("banner_control.on_tick", 60000);

        comm_center.reg_service("SvrShowOffShellTips", banner_control.show_off_shell_tips);
        comm_center.reg_service("SvrShowLackSpaceTips", banner_control.show_lack_space_tips);
        comm_center.reg_service("SrvJumpHomePageModule", banner_control.jump_home_page_module);
        comm_center.reg_service("SrvGetListColorFlag", banner_control.get_list_color_flag);
        comm_center.reg_service("SrvGetGameState", banner_control.handle_get_game_state);
        comm_center.reg_service("SvrShowGuideUpdateTips", banner_control.handel_guide_update_tips);
        comm_center.reg_service("SvrGetHasGameRunning", banner_control.handle_has_game_running);
        comm_center.reg_service("SvrLua_Banner_GoToGame", banner_control.goto_game);

        comm_center.listen_broadcast("Brdcst_Feeds_UnreadCount", "WGBannerList:feeds_unread_count_rsp");
        comm_center.listen_broadcast("Brdcst_Feeds_Unread_Report", "WGBannerList:query_feeds_unread_count_timer");
        comm_center.listen_broadcast("Brdcst_Feeds_SetLastReaded", "WGBannerList:feeds_set_last_readed");
        -- comm_center.listen_broadcast("Msg_MainWndShow", "banner_control.init_banner_list");
        comm_center.listen_broadcast("Msg_MainWndShow", "banner_control.handle_show_main_frame");
        comm_center.listen_broadcast("Msg_Show_BannerList", "banner_control.init_banner_list");
        comm_center.listen_broadcast("Msg_UserSelfRegionNotify", "banner_control.handle_userself_region_notify");
        comm_center.listen_broadcast("Msg_BatchLocalGameConfigData",
            banner_control.batch_handle_banner_info);
        comm_center.listen_broadcast("Msg_UpdateGameBaseInfo",
            banner_control.update_single_game_base_info);
        comm_center.listen_broadcast("Msg_PrivateGameDataUpdate",
            banner_control.update_private_banner_info);
        comm_center.reg_service("Svr_ShowDownloadGameConfigTips",
            banner_control.download_game_config_tips);
        comm_center.reg_service("Svr_UpdateSubscriptionList",
            banner_control.update_subscription_list);
        comm_center.listen_broadcast("Msg_BatchUpdateGameBaseInfo",
            banner_control.update_batch_game_base_info);
        comm_center.listen_broadcast("MsgTGPConfigMgr_UpdateClientMode",
                                     "banner_control.on_color_mode_update");
    end;

    inner_log = function (msg, core_msg)
        base_utility.log(string.format("[banner_control] %s", msg), core_msg);
    end;

    init_banner_list = function(param_tbl)
        if param_tbl == nil or param_tbl.isfirst == 0 then
            return
        end
        banner_control.inner_log("init_banner_list.");
        if 0 == banner_view.ub_game_list_panel_id_ then
            local dlg_list = ui_utility.get_ctrl_id_by_cid(CID_WEGAME_DIALOG_LIST);
            local ub_game_list_panel_id = ui_utility.get_ctrl_id_by_path(dlg_list, "pnlList\\LeftPanelContainer\\UBGameListPanel");
            banner_view.more_menu_btn_id_ = ui_utility.get_ctrl_id_by_path(dlg_list, "pnlList\\LeftPanelContainer\\btnMoreMenu");
            ui_utility.setproperty_by_id(banner_view.more_menu_btn_id_, "BackgroundHover",
                banner_control.color_text_);
            if ub_game_list_panel_id ~= Tenio.INVALID_CONTROLID then
                banner_view.ub_game_list_panel_id_ = ub_game_list_panel_id;

                local ub_game_list_ptr = ui_utility.get_ctrl_ptr_by_id(ub_game_list_panel_id);
                if ub_game_list_ptr ~= nil then
                    ub_game_list_ptr:LoadContent();
                end
                -- james
                banner_view.InitView(); 

                local game_list_ctrl_id = ui_utility.get_ctrl_id_by_path(ub_game_list_panel_id
                                        , "Ctn_GamesPnl\\pnlGameList");
                banner_view.init_banner_ctrl(game_list_ctrl_id);

                banner_view.init_banner_list(); 

                local game_list_count = banner_model.visible_game_list.count;
                local subscription_list = banner_model.get_visible_subscription_list();
                local subscription_list_count = #subscription_list;
                -- 游戏列表加载优化 
                --if game_list_count == 0 and subscription_list_count > 0 then
                --    banner_control.ensure_subscription_list_show();
                --else
                    banner_control.ensure_my_game_list_show();
                --end
                local color_data_config = comm_center.call_service("SvrTGPConfigMgr_GetColorMode", {});
                if color_data_config ~= nil and color_data_config.color_mode ~=nil then
                    local color_data_param = {color_mode = color_data_config.color_mode };
                    banner_control.on_color_mode_update(color_data_param);
                end;
            end;

            -- 发送初始化通知
            event_center.send_event(banner_event.INIT_BANNER_LIST, "");
        end
    end;

    goto_game = function (param)
        if param == nil or param.game_id == nil or  param.game_id  == 0 then
            return;
        end;
        local game_id = param.game_id;
        local new_param = { };
        new_param.module_id = game_id;
        new_param.check_attach = nil;
        new_param.ctrl_id = nil;
        event_center.send_event(banner_event.JUMP_MODULE_WEB, base_utility.table_to_json(new_param));
    end;

    -- 切换到指定的banner节点上
    focus_banner_item = function (event_id, json_str)
        banner_control.inner_log("focus_banner_item");
        local params = base_utility.json_to_table(json_str);
        local module_id = nil;
        if params ~= nil and params.module_id ~= nil and "" ~= params.module_id then
            if params.attach_info ~= nil and params.attach_info.main_game_id ~= nil then
                module_id = params.attach_info.main_game_id;
            else
                local attach_info = comm_center.call_service("Svr_CheckHasAttachRel", 
                               {game_id = tonumber(params.module_id), has_attach = 0, main_game_id = 0});
                if attach_info ~= nil and attach_info.has_attach == 1 and attach_info.main_game_id ~= 0 then
                    module_id = attach_info.main_game_id;
                else
                    module_id = tonumber(params.module_id);
                end;
            end;
            if module_id == GAME_ID.GAME_ID_SHOP or
                module_id == GAME_ID.GAME_ID_NETBAR or 
                module_id == GAME_ID.GAME_ID_GAME_LIVE or 
                module_id == GAME_ID.GAME_ID_TESTZONE or 
                module_id == GAME_ID.GAME_ID_CHINATOWN then
                return;    -- 不处理这2个game id的消息
            end
            banner_control.inner_log("[focus_banner_item] module_id:" .. module_id);
            if module_id ~= banner_model.last_selected_game_id_ then
                banner_view.focus_banner_item(module_id, params.ctrl_id);
            end
        end
    end;

    -- 更新banner游戏列表
    update_visible_game_list = function ()
        banner_control.inner_log("update_visible_game_list");
        
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if game_lib == nil then return end
        banner_model.is_netbar = game_lib:get_bind_channel_id();
        -- 0：按游戏id; 1：按名字; 2：按人气; 3：按日期;
        local game_list_sort = 9;   -- 此处用9表示不进行任何排序
        if banner_model.is_netbar == 1 then
            -- 网吧版本
            local visible_game_list = ierd_tgp.game_library.Game_list:new();
            game_lib:get_visible_games(visible_game_list);
            -- 获取当前游戏
            local ncurrentid = 0;
            local game_category = ierd_tgp.game_library.GameCategory:new();
            game_lib:get_game_category(0, banner_model.GAME_LIST_TYPE_CURRENT_GAME, 0, game_list_sort, game_category);
            if game_category.game_count > 0 then
                ncurrentid = game_category.game_list[0];
            end
            game_category:delete();
            local nindex = 0;
            if ncurrentid ~= 0 then
                banner_model.visible_game_list.game_id_list[0] = ncurrentid;
                nindex = 1;
            end
            local visible_game_count = game_lib:GetNetbarVisibleGameCount();
            local show_count = visible_game_list.count;
            if visible_game_count < show_count then
                show_count = visible_game_count;
            end
            for i = 0, show_count - 1 do
                if visible_game_list.game_id_list[i] ~= ncurrentid then
                    banner_model.visible_game_list.game_id_list[nindex] = visible_game_list.game_id_list[i];
                    nindex = nindex + 1;
                end
            end
            banner_model.visible_game_list.count = nindex;
            visible_game_list:delete();
            banner_view.refresh_game_list(true);
        else
            game_lib:get_visible_games(banner_model.visible_game_list);
            banner_control.inner_log(
                "update_visible_game_list, count: " .. banner_model.visible_game_list.count);
            banner_view.refresh_game_list(true);
        end

        -- 提前下载banner icon
        base_utility.add_interval("banner_control.delay_predownload_banners_icon", 5 * 1000, 0);

        -- 用于通知更新"我的游戏"游戏数量
        local update_banner_game_list_param = {};
        update_banner_game_list_param.game_count = banner_model.visible_game_list.count;
        event_center.send_event(banner_event.UPDATE_BANNER_GAME_LIST,
                                base_utility.table_to_json(update_banner_game_list_param));

        -- 是否需要滚动到顶端
        if banner_model.visible_game_list.game_id_list ~= nil and
           banner_model.visible_game_list.game_id_list[0] ~= nil then
            local cur_first_game_id = banner_model.visible_game_list.game_id_list[0];
            if banner_model.pre_visible_game_list_count < banner_model.visible_game_list.count and
               banner_model.pre_visible_game_list_first_game_id ~= cur_first_game_id then
                event_center.send_event(mainframe_event.SCROLL_TO_COMPOSELIST_TOP, "");
            end
            banner_model.pre_visible_game_list_count = banner_model.visible_game_list.count;
            banner_model.pre_visible_game_list_first_game_id = cur_first_game_id;
        end
        
    end;

    set_game_list_type = function (list_type)
        banner_model.game_list_type = list_type;
    end;

    -- 更新游戏区服信息
    update_game_servers = function (event_id, json_str)
        banner_control.inner_log("[update_game_servers] json_str: " .. json_str);

        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if game_lib ~= nil then
            local params = base_utility.json_to_table(json_str);
            if (params == nil) or (params.game_id == 0) then
                banner_control.update_all_games_servers();
                banner_control.inner_log("[update_game_servers] total game_count: " .. banner_model.all_game_servers.game_count);
            else
                local game_servers = banner_model.get_game_servers(params.game_id);
                if (game_servers == nil) then
                    banner_model.all_game_servers.gameid2servers[params.game_id] = ierd_tgp.game_library.GameServers:new();
                    game_servers = banner_model.all_game_servers.gameid2servers[params.game_id];
                    banner_model.all_game_servers.game_count = banner_model.all_game_servers.game_count + 1;
                end;
                
                game_lib:get_game_servers(params.game_id, game_servers);
                banner_control.inner_log("[update_game_servers] new game: " .. params.game_id);
            end;
            
            event_center.send_event(banner_event.UPDATE_GAME_SERVERS, json_str);
        end;
    end;

    -- 更新游戏状态
    update_game_state = function (event_id, json_str)
        banner_control.inner_log("[update_game_state] refresh_state, json_str: " .. json_str);

        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if game_lib == nil then return end;
        local params = base_utility.json_to_table(json_str);
        if nil == params then
            banner_control.inner_log("[update_game_state]params is nil");
            return;
        end

        if 0 == params.game_id then
            banner_control.update_all_game_state_info();
            banner_control.inner_log("[update_game_state] total count: " .. banner_model.game_state_list.count);
        else
            local game_state = banner_model.get_game_state(params.game_id);
            if (game_state == nil) then
                local count = banner_model.game_state_list.count;
                banner_model.game_state_list.game_state[count] =
                    ierd_tgp.game_library.GameState:new();
                game_state = banner_model.game_state_list.game_state[count];
                banner_model.game_state_list.count = count + 1;
            end 
            game_lib:get_game_state(params.game_id, game_state);
            banner_control.inner_log("[update_game_state] new game: " .. params.game_id .. ", state: " .. game_state.iState);
        end
            
        banner_view.refresh_game_state(params.game_id);

        event_center.send_event(banner_event.UPDATE_GAME_STATE, json_str);
    end;

    -- 更新助手状态
    update_plugin_state = function (event_id, json_str)
        banner_control.inner_log("[update_plugin_state] json_str: " .. json_str);

        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if game_lib ~= nil then
            local params = base_utility.json_to_table(json_str);
            game_lib:get_all_plugin_states(banner_model.plugin_state_list);
            banner_control.inner_log("[update_plugin_state] total count: " .. banner_model.plugin_state_list.count);
            
            event_center.send_event(banner_event.UPDATE_PLUGIN_STATE, json_str);
        end;
    end;

    update_predownload_state = function(event_id, json_param)
        local param = base_utility.json_to_table(json_param);
        if param.game_id ~= nil and param.game_id ~= 0 then
           banner_view.refresh_preupdate_state(param.game_id);
        end;
    end;

    json2game_id = function (json_str)
        local param = base_utility.json_to_table(json_str);
        local game_id = 0;
        if param ~= nil and param.game_id ~= nil then
            game_id = param.game_id;
        else
            banner_control.inner_log("json2game_id, param is nil");
        end
    
        return game_id;
    end;

    handle_json_banner_config = function(config)
        local game_id = 0;
        if config ~= nil and type(config) == 'table'and config.game_id ~= nil then
            game_id = tonumber(config.game_id);
        end
        --banner_control.inner_log("handle_json_banner_config .. " .. tostring(game_id) ..
        --    " - " .. base_utility.table_to_json(config));
        if game_id == 0 then
            return
        end
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        local module_url = config.module_url;
        -- TODO(amadeusyu): 3.37全量后，将oss首页地址改为我的应用页，再去掉这个逻辑
        if game_id == GAME_ID.GAEM_ID_HOME_PAGE then
            module_url = web_utility.profile_sub_tab_info["GAME"].url;
        end
        local json_sub_urls = "";
        if config.sub_url_list ~= nil and config.sub_url_list ~= "" then
            json_sub_urls = config.sub_url_list;
        end
        -- 使用新的背景颜色配置
        local module_color = ui_utility.convert_hex_color_to_str(config.background_color);
        if module_color == nil or module_color == "" then
            -- 使用默认配置
            module_color = banner_model.def_module_color;
        end
        -- banner list背景色
        --local banner_color = ui_utility.convert_hex_color_to_str(config.banner_color);
        local banner_color = banner_model.def_banner_color;
        if banner_color == nil or banner_color == "" then
            banner_color = banner_model.def_banner_color;
        end
        if config.module_image == nil then
            module_image = "ONEIMAGE:NONE:";
        else
            module_image = "ONEIMAGE:"..config.module_image..";Stretch;null;";
        end
        local plugin_setting = "";
        if config.plugin_setting ~= nil then
            plugin_setting = config.plugin_setting;
        end
        local helper_simple_area_setting = "";
        if config.helper_simple_area_setting ~= nil then
            helper_simple_area_setting = config.helper_simple_area_setting;
        end
        local download_report = 0;
        if config.download_report ~= nil and config.download_report ~= "" then
            download_report = tonumber(config.download_report);
        end
        if game_id ~= nil and download_report == 1 and game_lib ~= nil then
            game_lib:SetDownloadGameReport(game_id);
        end
            
        if game_id ~= nil and module_url ~= nil then
            banner_control.inner_log("set banner_model.module_info " .. tostring(game_id));
            banner_model.module_info[game_id] = {
                name = config.name,   -- 后续会废弃，不要再使用
                type = config.type,
                game_id = game_id,
                module_url = module_url,
                module_color = module_color,
                module_image = module_image,
                background_color = config.background_color,
                background_image = config.background_image,
                bottom_background_color = ui_utility.convert_hex_color_to_str(config.bottom_background_color),
                plugin_setting = plugin_setting,
                helper_simple_area_setting = helper_simple_area_setting,
                image_position = config.image_position,
                toolBar_BG = config.toolBar_BG,
                toolBar_shadow = config.toolBar_shadow,
                download_report = download_report,
                download_gifts = config.download_gifts,
                gift_icon_disable = config.gift_icon_disable,
                gift_icon = config.gift_icon,
                sub_url_list = json_sub_urls,
                banner_color = banner_color,
                multi_game_protocol_config = config.multi_game_protocol_config,
                };
        end;
    end;

    convert_string_to_time = function(date)
        local year = string.sub(date , 1, 4);
        local month = string.sub(date , 6, 7);  
        local day = string.sub(date , 9, 10);  
        local hour = string.sub(date , 12, 13);  
        local min = string.sub(date , 15, 16);  
        local sec = string.sub(date , 18, 19);

        return os.time({year=year, month=month, day=day, hour=hour,min=min,sec=sec})
    end;

    on_json_check_version_interval = function(time_stamp)
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if nil ~= game_lib then
            if banner_control.check_repair_cfg_data ~= nil then
                banner_control.check_game_repair_status(
                    banner_control.check_repair_cfg_data, game_lib);
            end
            local tpfui =
                base_utility.get_component_adapter("ITpf_ui", "ierd_tgp.tpf_ui.GetTPFUI();");
            if tpfui ~= nil then
                tpfui:RemoveInterval('banner_control.on_json_check_version_interval');
            end
        end
    end;

    handle_json_check_version = function(data_table)
        base_utility.log("[banner_control]handle_json_check_version");
        if data_table ~= nil then
            banner_control.check_repair_cfg_data = data_table;
            local game_lib =base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
            if game_lib ~= nil then
                banner_control.check_game_repair_status(data_table, game_lib);
            else
                local tpfui = base_utility.get_component_adapter("ITpf_ui","ierd_tgp.tpf_ui.GetTPFUI();");
                if tpfui ~= nil then
                    tpfui:AddInterval("banner_control.on_json_check_version_interval", 10000);
                end
            end
        end
    end;

    check_game_repair_status = function(data_table, game_lib)
        -- channel_id : 0=常规版；1=网吧版；2=所有版本
        -- flag : 0 - 关闭；1 - 打开

        banner_model.is_netbar = game_lib:get_bind_channel_id();
        if data_table ~= nil and table.getn(data_table) > 0 then
            for i, data in pairs(data_table) do
                banner_control.need_repair = 1;--默认开启修复
                if data_table[i] ~= nil and data_table[i]['game_id'] ~= nil 
                    and data_table[i]['channel_id'] ~= nil and data_table[i]['flag'] ~= nil then
                    local game_id = tonumber(data_table[i]['game_id']);
                    local open_channel_id = tonumber(data_table[i]['channel_id']);
                    local game_need_repair = tonumber(data_table[i]['flag']);
                    if open_channel_id == banner_control.all_channel or 
                        open_channel_id == banner_model.is_netbar then
                        if game_need_repair == 0 then
                            -- 网吧环境不会保存修复记录，配置可支持关闭修复，优化游戏启动速度
                            banner_control.need_repair = 0;--关闭
                        end
                    end
                    if game_id ~= nil then
                        game_lib:set_launch_repair_game_flag(game_id, banner_control.need_repair);
                        base_utility.log("[banner_control][check_game_repair_status] game_id="
                            .. game_id .. " need_repair= ".. banner_control.need_repair);
                    end
                end
            end
        end
    end;

    get_check_version_flag = function()
        local result =  banner_control.need_repair==1 and true or false;
        base_utility.log("get_check_version_flag :" .. tostring(result));
        return result;
    end;

    on_get_json_cfg = function(event_id, json_str)
        local config_table = base_utility.json_to_table(json_str);
        if config_table == nil then
            return;
        end;
        if config_table["json"] ~= nil and type(config_table["json"]) == 'table' and config_table["json"]["data"] ~= nil then
            if config_table["name"] == "wg_banner_config" then
                banner_control.inner_log("[on_get_json_cfg] wg_banner_config");
                banner_control.handle_other_banner_config(config_table["json"]["data"]);
            end
        end
    end;

    on_tick = function()
        collectgarbage("collect");
    end;

    -- 当前是否有游戏正在运行中. 1为有，0为无
    has_game_is_running = function()
        return banner_model.has_game_is_running();
    end;

    -- 获取当前可见游戏列表
    get_game_visible_by_gameid = function(game_id)
        local visible_list = banner_model.visible_game_list;
        if 0 == visible_list.count then
            return false;
        end
        for i = 0, visible_list.count - 1 do
            if game_id == visible_list.game_id_list[i] then
                return true;
            end            
        end
        return false;   
    end;

    -- 不通过game_id获取配置，由页面控制框架颜色
    change_client_color_and_image = function(json)
        local change_color = nil;
        local change_image = nil;
        local param = base_utility.json_to_table(json);
        if param == nil or param.data == nil or param.data.color == nil then
            banner_control.inner_log("missed param.data.color!");
            return;
        end
        -- 颜色
        change_color = tostring(param.data.color);
        if change_color == nil or string.find(change_color, "COLOR:RGB:%d+,%d+,%d+") == nil then
            banner_control.inner_log("error color param!");
            return;
        end
        -- 底图
        change_image = param.data.image;
        if change_image == nil or change_image == "" then
            change_image = "ONEIMAGE:NONE:";
        end

        -- mainframe_control.set_module_color_and_image(change_color, change_image);

        if param.success ~= nil then
            local rsp_table = {};
            rsp_table.retCode = 0;
            rsp_table.msg = "";
            rsp_table.src = 0;
            rsp_table.data = {};
            web_utility.lua_call_js_ex(param.success, 
                base_utility.table_to_json(rsp_table), CID_MAINFRAME_QBWEB);
        end
    end;

    set_module_color_and_image = function(json)
        local module_color = nil;
        local module_image = nil;
        local param = base_utility.json_to_table(json);
        if param == nil or param.data == nil or param.data.module_id == nil then
            banner_control.inner_log("missed param.data.module_id!");
            return;
        end
        local module_info = banner_model.get_banner_module_info_by_game_id(param.data.module_id);
        if module_info ~= nil then
            -- 使用配置好的背景颜色和图片
            module_color = module_info.module_color;
            module_image = module_info.module_image;
        end 
        if module_color == nil then
            -- 默认使用游戏中心的背景颜色
            module_color = banner_model.def_module_color;
        end
        if module_image == nil then
            -- 没有配置背景图
            module_image = "ONEIMAGE:NONE:";
        end
        -- mainframe_control.set_module_color_and_image(module_color, module_image);

        if param.success ~= nil then
            local rsp_table = {};
            rsp_table.retCode = 0;
            rsp_table.msg = "";
            rsp_table.src = 0;
            rsp_table.data = {};
            web_utility.lua_call_js_ex(param.success, 
                base_utility.table_to_json(rsp_table), CID_MAINFRAME_QBWEB);
        end
    end;

    HandleQBlinkRelaunch = function()
        local callback_func = web_register_center.get_func_by_browser(
            "jc_set_app_status", CID_MAINFRAME_QBWEB);
        if callback_func ~= nil then
            base_utility.remove_interval("banner_control.HandleQBlinkRelaunch");
            banner_control.jump_module_web(0, banner_control.jump_module_web_json, true);
            return;
        end;
        banner_control.rejump_number = banner_control.rejump_number + 1;
        if banner_control.rejump_number >= 5 then
            base_utility.remove_interval("banner_control.HandleQBlinkRelaunch");
        end;
    end;
    -- 跳转指定模块页面
    jump_module_web = function (event_id, json_str, skip_relaunch)
        banner_control.inner_log(string.format("[jump_module_web]module_id:%s", json_str));
        local json_params = base_utility.json_to_table(json_str);
        if nil == json_params or nil == json_params.module_id then
            banner_control.inner_log("[jump_module_web]json_params is nil");
            return;
        end

        local param = {};
        param.module_id = json_params.module_id;
        local module_info = banner_model.get_banner_module_info_by_game_id(json_params.module_id);
        if module_info ~= nil then
            -- 使用配置好的背景颜色和图片
            param.module_color = module_info.module_color;
            param.module_image = module_info.module_image;
            param.module_url = module_info.module_url;
        else
            -- 使用默认的背景颜色
            param.module_color = banner_model.def_module_color;
        end 
        if param.module_image == nil then
            -- 没有配置背景图
            param.module_image = "ONEIMAGE:NONE:";
        end
        if json_params.module_url ~= nil then
            param.module_url = json_params.module_url;
        end
        
        if json_params.check_attach ~= nil then
            param.check_attach = json_params.check_attach;
        end
        param.attach_info = wegame_mainframe_control.get_selected_attach_info(tonumber(param.module_id));
         -- check qblink crashed
        local nQBWebID = ui_utility.uilib():GetControlIDbyCustomID(CID_MAINFRAME_QBWEB);
        local pControl = ui_utility.uilib():GetControlPtr(nQBWebID);
        local pQBWeb = tolua.cast(pControl, "Tenio::IQBlinkWebBrowser");
        if pQBWeb ~= nil then
            if skip_relaunch == nil or skip_relaunch == false then
                local relaunch_qb = pQBWeb:CheckAndRelaunchQBlink(banner_control.const_frame_url_str);
                if relaunch_qb == true then
                    banner_control.jump_module_web_json = json_str;
                    base_utility.add_interval("banner_control.HandleQBlinkRelaunch", 1000);
                    return;
                end;
            end;
        end

        -- 增加回调web的函数
        local callback_func = web_register_center.get_func_by_browser(
            "jc_set_app_status", CID_MAINFRAME_QBWEB);
        param.callback_func = callback_func;
        if nil ~= json_params.ctrl_id then
            param.ctrl_id = json_params.ctrl_id;
        end
        event_center.send_event(banner_event.FOCUS_BANNER_ITEM,
            base_utility.table_to_json(param));
    end;

    update_all_games_servers = function()
        banner_control.inner_log("update_all_games_servers");
        banner_model.uninit_all_game_servers();
        banner_model.init_all_game_servers();

        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if nil == game_lib then
            banner_control.inner_log("[update_all_games_servers]game_lib is nil");
            return;
        end;

        local servers_game_id_info = ierd_tgp.game_library.AllServersGameIdInfo:new();
        if nil == servers_game_id_info then
            banner_control.inner_log("[update_all_games_servers]AllServersGameIdInfo:new() fail");
            return;
        end;
        
        game_lib:GetAllServersGameIdInfo(servers_game_id_info);
        banner_model.all_game_servers.game_count = servers_game_id_info.game_count;
        banner_model.all_game_servers.acce_enabled = servers_game_id_info.acce_enabled;

        for i = 0, (servers_game_id_info.game_count - 1) do
            local game_id = servers_game_id_info.game_id_list[i];
            banner_model.all_game_servers.gameid2servers[game_id] = ierd_tgp.game_library.GameServers:new();
            game_lib:get_game_servers(game_id, banner_model.all_game_servers.gameid2servers[game_id]);
        end;
        servers_game_id_info:delete();
    end;

 
    update_all_game_base_info = function ()
        banner_control.inner_log("update_all_game_base_info", true);

        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if nil == game_lib then
            banner_control.inner_log("[update_all_game_base_info]game_lib is nil");
            return;
        end;

        local base_info_id_list = ierd_tgp.game_library.GameBaseInfoIDList:new();
        if nil == base_info_id_list then
            banner_control.inner_log("[update_all_game_base_info]GameBaseInfoIDList:new() fail");
            return;
        end;
        
        game_lib:GetAllGameBaseInfoIDList(base_info_id_list);
        banner_control.resize_game_base_info_list(base_info_id_list.count);
        banner_control.inner_log("[update_all_game_base_info]count: "..base_info_id_list.count,true);

        for i = 0, (base_info_id_list.count - 1) do
            local game_id = base_info_id_list.game_id_list[i];
            if nil == banner_model.game_base_info_list.game_base_info[i] then
                banner_model.game_base_info_list.game_base_info[i] = ierd_tgp.game_library.GameBaseInfo:new();
            end
            game_lib:GetGameBaseInfo(game_id, banner_model.game_base_info_list.game_base_info[i]);
        end;
        base_info_id_list:delete();

        -- 有游戏基本信息更新，刷新游戏列表
        banner_view.refresh_game_list(true);
        -- 通知游戏基本信息更新完成
        comm_center.send_broadcast("i_broadcast_game_base_info_update_finish", {});
    end;

    update_batch_game_base_info = function(param_tbl)
        banner_control.inner_log("update_batch_game_base_info", true);
        if param_tbl == nil or param_tbl.game_idList == nil or
            type(param_tbl.game_idList) ~= 'table' then
            return
        end
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if nil == game_lib then
            banner_control.inner_log("[update_batch_game_base_info]game_lib is nil");
            return;
        end;

        for index, game_id in ipairs(param_tbl.game_idList) do
            local find_it = false;
            for i = 0, (banner_model.game_base_info_list.count - 1) do
                if banner_model.game_base_info_list.game_base_info[i].id == game_id then
                    find_it = true;
                    break;
                end;
            end
            if not find_it then
                local count = banner_model.game_base_info_list.count;
                banner_model.game_base_info_list.game_base_info[count]
                    = ierd_tgp.game_library.GameBaseInfo:new();
                game_lib:GetGameBaseInfo(game_id,
                    banner_model.game_base_info_list.game_base_info[count]);
                banner_model.game_base_info_list.count = count + 1;
            end
        end
        -- 有游戏基本信息更新，刷新游戏列表
        banner_view.refresh_game_list(true);
        -- 通知游戏基本信息更新完成
        comm_center.send_broadcast("i_broadcast_game_base_info_update_finish", {});
    end;

    update_all_game_state_info = function()
        banner_control.inner_log("update_all_game_state_info");
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if nil == game_lib then
            banner_control.inner_log("[update_all_game_state_info]game_lib is nil");
            return;
        end;
        local data_tbl = comm_center.call_service("Svr_GetGameStateGameIdList", {});
        if data_tbl ~= nil and data_tbl.game_id_list ~= nil and
            type(data_tbl.game_id_list) == 'table' then
             local count = table.getn(data_tbl.game_id_list);
             banner_control.resize_game_state_list(count);
             banner_control.inner_log("[update_all_game_state_info]count: "..count, true);
             for i = 0, (count - 1) do
                local game_id = data_tbl.game_id_list[i + 1];   -- table数组下标从1开始
                if nil == banner_model.game_state_list.game_state[i] then
                    banner_model.game_state_list.game_state[i] =
                        ierd_tgp.game_library.GameState:new();
                end
                game_lib:get_game_state(game_id, banner_model.game_state_list.game_state[i]);
             end 
        end
    end;


    resize_game_base_info_list = function (new_size)
        if new_size < banner_model.game_base_info_list.count then
            for i = new_size, banner_model.game_base_info_list.count - 1 do
                banner_model.game_base_info_list.game_base_info[i]:delete();
                banner_model.game_base_info_list.game_base_info[i] = nil;
            end
        end
        banner_model.game_base_info_list.count = new_size;
    end;

    resize_game_state_list = function (new_size)
        if new_size < banner_model.game_state_list.count then
            for i = new_size, banner_model.game_state_list.count - 1 do
                banner_model.game_state_list.game_state[i]:delete();
                banner_model.game_state_list.game_state[i] = nil;
            end
        end
        banner_model.game_state_list.count = new_size;
    end;

    update_game_base_info_for_lua = function ()
        banner_control.inner_log("update_game_base_info_for_lua");
        banner_control.update_all_game_base_info();
    end;

    update_single_game_base_info = function(param_tbl)
        local game_id = 0;
        if param_tbl ~= nil and param_tbl.game_id ~= nil then
            game_id = param_tbl.game_id;
        end
        if game_id == 0 then return end;
        banner_control.inner_log("update_single_game_base_info, " .. tostring(game_id));
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if nil == game_lib then
            banner_control.inner_log("[update_single_game_base_info]game_lib is nil");
            return;
        end;

        local find_it = false;
        for i = 0, (banner_model.game_base_info_list.count - 1) do
            if banner_model.game_base_info_list.game_base_info[i].id == game_id then
                game_lib:GetGameBaseInfo(game_id, banner_model.game_base_info_list.game_base_info[i]);
                find_it = true;
                break;
            end;
        end;
        if not find_it then
            local count = banner_model.game_base_info_list.count;
            banner_model.game_base_info_list.game_base_info[count]
                = ierd_tgp.game_library.GameBaseInfo:new();
            game_lib:GetGameBaseInfo(game_id,
                banner_model.game_base_info_list.game_base_info[count]);
            banner_model.game_base_info_list.count = count + 1;

            -- 通知游戏基本信息更新完成
            comm_center.send_broadcast("i_broadcast_game_base_info_update_finish",
                {game_id = game_id});
        end
        -- 更新banner信息
        local banner_config_tbl = comm_center.call_service("Svr_GetGameBannerConfigData",
            {game_id = game_id});
        if banner_config_tbl ~= nil and banner_config_tbl.banner_config ~= nil and
             banner_config_tbl.banner_config ~= "" then
            local wg_banner_config = base_utility.json_to_table(banner_config_tbl.banner_config);
            if wg_banner_config ~= nil and type(wg_banner_config) == 'table' and
                 not base_utility.is_empty_table(wg_banner_config) then
                banner_control.handle_json_banner_config(wg_banner_config);
                local param = { game_id = game_id };
                event_center.send_event(banner_event.UPDATE_BANNER_CONFIG,
                    base_utility.table_to_json(param));
            end
        end
        -- 提前下载banner图标
        banner_control.predownload_banner_icon(banner_model.get_game_base_info(game_id));
    end;

    on_login_success = function ()
        -- 拉取关注的游戏列表
        local post_data = {};
        post_data["item"] = 3;
        post_data["uin"] = login_model.current_uin;
        post_data["callback"] = "get_follow_game_list";
        base_utility.curl_request_async(
            banner_model.follow_game_list_req_url,
            "banner_model.on_get_follow_game_list", false, post_data, true);

        -- 拉取预约游戏列表
        banner_model.load_local_subscription_info();
        banner_model.query_subscription_config(0);
        --banner_model.query_subscription_list();

    end;

    is_game_type_item = function(game_id)
        local is_game_item = true; 
        if game_id == nil then
            return false;
        end

        local num_game_id = tonumber(game_id);
        if GAME_ID.GAME_ID_PERSON_CENTER == num_game_id or
            GAME_ID.GAME_ID_TGP == num_game_id or
             GAME_ID.GAEM_ID_HOME_PAGE == num_game_id or
              GAME_ID.GAME_ID_GAME_LIVE == num_game_id or
                GAME_ID.GAME_ID_SHOP == num_game_id or
                 GAME_ID.GAME_ID_NETBAR == num_game_id or 
                  GAME_ID.GAME_ID_TESTZONE == num_game_id or
                  GAME_ID.GAME_ID_CHINATOWN == game_id then
            is_game_item = false;
        end

        return is_game_item;
    end;

    show_off_shell_tips = function (input)
        base_utility.log(string.format(
            "[banner_control][show_off_shell_tips]input:%s",
            base_utility.table_to_json(input)));
        if nil == input then
            return;
        end

        local game_id = input.game_id;
        local game_type = input.game_type;
        local game_server_id = input.server_id;
        local game_ver = input.ver;
        banner_view.show_off_shell_tips(game_id, game_type, game_server_id, game_ver);
    end;

    show_lack_space_tips = function (input)
        base_utility.log(string.format(
            "[banner_control][show_lack_space_tips]input:%s",
            base_utility.table_to_json(input)));
        if nil == input then
            return;
        end
        banner_view.show_lack_space_tips(input.game_id, input.server_id);
    end;

    jump_home_page_module = function()
        local param = {};
        if banner_model.last_selected_game_id_ == nil then
            param.module_id = GAME_ID.GAEM_ID_HOME_PAGE;
        else
            param.module_id = banner_model.last_selected_game_id_; 
        end
        param.check_attach = 1;
        event_center.send_event(banner_event.JUMP_MODULE_WEB, base_utility.table_to_json(param));
    end;

    get_list_color_flag = function (data)
        if nil == data or nil == data.game_id then
            return;
        end

        local color_info = {};
        local module_info = banner_model.get_banner_module_info_by_game_id(data.game_id);
        if module_info ~= nil and module_info.banner_color ~= nil and module_info.banner_color ~= "" then
            color_info["color_flag"] = 0; -- 默认是浅色
        end

        if module_info ~= nil and module_info.banner_color == banner_model.def_banner_color then
            -- 如果是浅色，则设置浅色的背景色
            color_info["color_flag"] = 0;
        else
            -- 设置深色背景
            color_info["color_flag"] = 1;
        end
        return color_info;
    end;

    handle_show_main_frame = function (param_tbl)
        if param_tbl == nil or param_tbl.isfirst == 0 then
            return
        end 
        local game_lib =
            base_utility.get_component_adapter("IGame_library",
                "ierd_tgp.game_library.Get_game_library_adapter();");
        if game_lib ~= nil then
            game_lib:get_json_cfg("wg_banner_config");
            banner_control.load_game_launch_repair_cfg();
        end;
    end;

    load_game_launch_repair_cfg = function()
        local data = {key = "game_launch_repair_cfg"};
        local cfg = comm_center.call_service("i_svr_get_common_cfg", data);
        if nil == cfg then
            return;
        end
        
        if cfg.value == nil or cfg.value == "" then
            return;
        end

        local cfg_tb = base_utility.json_to_table(cfg.value);
        banner_control.handle_json_check_version(cfg_tb);
    end;

    handle_userself_region_notify = function(param_tbl)
    end;

    handle_get_game_state = function (data)
        if nil == data then
            return;
        end
        local state = banner_model.get_game_state(data.game_id);
        local result = {};
        result["game_id"] = data.game_id;
        result["state"] = state;
        return result;
    end;

    handel_guide_update_tips = function (data)
        if nil == data or nil == data.game_id or nil == data.tips_content then
            return;
        end

        if wegame_mainframe_view.show(false) then
            event_center.send_event(mainframe_event.MAINFRAME_WND_SHOWN, "");
        end;
        banner_model.guide_update_game_id = data.game_id;
        banner_model.guide_update_zone_id = data.zone_id;
        popup_wnd_model.set_game_icon(data.game_id);
        local error_msg = LoadStr("FRAME_BOTTOM_LAUNCH_UPDATE_TIPS");
        
        -- error_msg = error_msg .. "：" .. data.tips_content;

        local param = {
            position = "center",
            title = LoadStr("BANNER_MENU_TIPS"),
            width = 480,
            height = 230,
            titleIcon = "",
            icon = popup_wnd_model.icon_url,
            tipsIcon = poptips_icons.kError,
            descTitle = "",
            desc = error_msg,
            okBtn = {
                visible = "true",
                text = LoadStr("BANNER_MENU_CONFIRM"),
                handle = banner_control.handle_start_update,
            },
            cancelBtn = {
                visible = "false",
                text = LoadStr("BANNER_MENU_CANCEL"),
                handle = function()
                end,
            },
            game_id = data.game_id,
        }
        ui_utility.show_tips(param);
    end;

    handle_start_update = function ()
        popup_wnd_view.show_popup_wnd(FALSE);
        if 0 == banner_model.guide_update_game_id then
            return;
        end
        local action_info = {
            game_id_ = banner_model.guide_update_game_id,
            zone_id_ = banner_model.guide_update_zone_id,
            uid_ = 0,
            launch_op_from = ierd_tgp.game_library.LAUNCH_OP_FROM_LANDING_PAGE,
        };

        WGGameAction.excute_action(GameActions.kUpdateGame, action_info);
    end;

    batch_handle_banner_info = function(table_param)
        banner_control.inner_log("batch_handle_banner_info");
        if table_param ~= nil and table_param.data_info_list ~= nil and
            type(table_param.data_info_list) == 'table' then
            for i, config in ipairs(table_param.data_info_list) do
                if config ~= nil and config ~= "" then
                    local data_tb = base_utility.json_to_table(config);
                    if nil ~= data_tb and nil ~= data_tb.wg_banner_config then
                        banner_control.handle_json_banner_config(data_tb.wg_banner_config);
                    end
                end
            end
            local param = { game_id = 0 };
            event_center.send_event(banner_event.UPDATE_BANNER_CONFIG,
                base_utility.table_to_json(param));
        end
    end;

    handle_other_banner_config = function(data_table)
        banner_control.inner_log("handle_other_banner_config");
        if data_table ~= nil and type(data_table) == 'table' then
             for i, config in ipairs(data_table) do
                 if config ~= nil then
                    banner_control.handle_json_banner_config(config);
                 end
             end
             local param = { game_id = 0 };
             event_center.send_event(banner_event.UPDATE_BANNER_CONFIG,
                base_utility.table_to_json(param));
        end
    end;

    update_private_banner_info = function(table_param)
        banner_control.inner_log("update_private_banner_info");
        if table_param ~= nil and table_param.game_data_list ~= nil and
            type(table_param.game_data_list) == 'table' then
            for i, config in ipairs(table_param.game_data_list) do
                if config ~= nil and config ~= "" then
                    local data_tb = base_utility.json_to_table(config);
                    if nil ~= data_tb and nil ~= data_tb.wg_banner_config then
                        banner_control.handle_json_banner_config(data_tb.wg_banner_config);
                    end
                end
            end
            local param = { game_id = 0 };
            event_center.send_event(banner_event.UPDATE_BANNER_CONFIG,
                base_utility.table_to_json(param));
        end
    end;

    handle_has_game_running = function ()
        local data = {};
        data["has_game_running"] = banner_control.has_game_is_running();
        return data;
    end;

    download_game_config_tips = function(param_tbl)
        if param_tbl ~= nil and param_tbl.is_offline ~= nil then
            if param_tbl.is_offline then
                banner_control.download_game_config_tips_for_offline();
            else 
                banner_control.download_game_config_info_fail_for_add_game();
            end
        end
    end;

    download_game_config_info_fail_for_add_game = function()
        local desc_txt = LoadStr("BANNER_ACTION_DOWNLOAD_CONFIG_FAILER");
        local gamecfg_failed_param = {
            position = 'center',
            title = LoadStr("POP_TIPS_TIPS"),
            width = 480,
            height = 230,
            titleIcon = "",
            icon = "",
            tipsIcon = poptips_icons.kError,
            descTitle = "",
            desc = desc_txt,
            modal = false,
            cancelBtn = {
                visible = "false",
                text = LoadStr("POP_TIPS_CANCEL"),
                handle = function()
                end
            },
            okBtn = {
                close_win = true,
                visible = "true";
                text = LoadStr("POP_TIPS_BTN_OK"),
                handle = function()
                end
            },
        };
        ui_utility.show_tips(gamecfg_failed_param);
    end;

    download_game_config_tips_for_offline = function()
        local desc_txt = LoadStr("BANNER_ACTION_DOWNLOAD_CONFIG_FOR_OFFLINE");
        local gamecfg_failed_param = {
            position = 'center',
            title = LoadStr("POP_TIPS_TIPS"),
            width = 480,
            height = 230,
            titleIcon = "",
            icon = "",
            tipsIcon = poptips_icons.kError,
            descTitle = "",
            desc = desc_txt,
            modal = false,
            cancelBtn = {
                visible = "true",
                text = LoadStr("STR_LOGIN_LATER_LOGIN"),
                handle = function()
                end
            },
            okBtn = {
                close_win = true,
                visible = "true";
                text = LoadStr("STR_LOGIN_RELOGIN"),
                handle = function()
                    local   pLoginMgr = base_utility.get_component_adapter("ILogin_mgr",
                            "ierd_tgp.login_mgr.GetLoginMgr();");
                    if nil ~= pLoginMgr then
                        pLoginMgr:RestartTGP();
                    end;
                end
            },
        };
        ui_utility.show_tips(gamecfg_failed_param);
    end;

    predownload_all_banners_icon = function ()
        if nil == banner_model.game_base_info_list then
            return;
        end;
        
        for i = 0, (banner_model.visible_game_list.count - 1) do
            banner_control.predownload_banner_icon(
                banner_model.get_game_base_info(banner_model.visible_game_list.game_id_list[i]));
        end;

        for i = 0, (banner_model.visible_game_list.count - 1) do
            banner_control.predownload_other_game_icon(
                banner_model.get_game_base_info(banner_model.visible_game_list.game_id_list[i]));
        end;
    end;

    predownload_banner_icon = function (base_info)
        if nil ~= base_info then
            if nil ~= base_info.banner_mini_icon_url and 
            "" ~= base_info.banner_mini_icon_url then
                base_utility.download_files(base_info.banner_mini_icon_url);
            end
        end
    end;

    predownload_other_game_icon = function (base_info)
        if nil ~= base_info then
            if nil ~= base_info.icon_url and "" ~= base_info.icon_url then
                base_utility.download_files(base_info.icon_url);
            end
            if nil ~= base_info.banner_icon_url and "" ~= base_info.banner_icon_url then
                base_utility.download_files(base_info.banner_icon_url);
            end
            if nil ~= base_info.poster_url and "" ~= base_info.poster_url then
                base_utility.download_files(base_info.poster_url);
            end
            if nil ~= base_info.poster_url_v and "" ~= base_info.poster_url_v then
                base_utility.download_files(base_info.poster_url_v);
            end
        end
    end;

    banner_report = function(action, game_id)
        local   qosData = ierd_tgp.tpf_ui.LuaQosDataEx:new();
        local   kvData = {};
        kvData["operation" ] = action;
        if nil ~= game_id then
            kvData["game_id"] = game_id;
        end
        qosData.oc_type    = 1;
        qosData.qos_kind   = ierd_tgp.adapt_for_imports.qos.Qos_kind.kGameUpdateLackSpace;
        qosData.game_id = game_id;
        qosData.str_action = "main_window";
        qosData.str_type   = "app_banner";
        qosData.str_json   = base_utility.table_to_json(kvData);
        base_utility.lua_qos_ex(qosData);
        qosData:delete();
    end;

    update_subscription_list = function(args)
        base_utility.log("service update_subscription_list called");
        banner_model.query_subscription_list();
    end;

    toggle_my_game_list = function()
        banner_view.show_subscription_list(false);
        if banner_view.is_my_game_list_show() then
            banner_view.show_my_game_list(false);
        else
            banner_view.show_my_game_list(true);
        end
    end;

    toggle_subscription_list = function()
        banner_view.show_my_game_list(false);
        if banner_view.is_subscription_list_show() then
            banner_view.show_subscription_list(false);
        else
            banner_view.show_subscription_list(true);
        end
    end;

    ensure_my_game_list_show = function()
       if not banner_view.is_my_game_list_show() then
            banner_control.toggle_my_game_list();
       end
    end;

    ensure_subscription_list_show = function()
        if not banner_view.is_subscription_list_show() then
            banner_control.toggle_subscription_list();
        end
    end;

    on_my_game_list_switch_click = function()
        banner_control.toggle_my_game_list();
    end;

    on_subscription_list_switch_click = function()
        banner_control.toggle_subscription_list();
    end;

    on_game_start = function(event_id, data)
    end;

    delay_predownload_banners_icon = function(index)
        base_utility.remove_interval("banner_control.delay_predownload_banners_icon", index);
        if nil == banner_model.game_base_info_list then
            return;
        end;
        local insert_count = 0;
        if index + banner_model.ITEM_COUNT_PER_TIME < banner_model.visible_game_list.count then
            insert_count = banner_model.ITEM_COUNT_PER_TIME;
        else 
            insert_count = banner_model.visible_game_list.count - index;
        end
        -- 增加节点数量
        local last_index = index + insert_count - 1;
        if insert_count > 0 then
            for i = index, last_index do
                banner_control.predownload_banner_icon(
                   banner_model.get_game_base_info(banner_model.visible_game_list.game_id_list[i]));
                -- 没看出来这些图片在哪有使用，屏蔽相关预下载
                -- banner_control.predownload_other_game_icon(
                -- banner_model.get_game_base_info(banner_model.visible_game_list.game_id_list[i]));
            end
        end
        if last_index + 1 < banner_model.visible_game_list.count then
             base_utility.add_interval("banner_control.delay_predownload_banners_icon",
                5 * 1000, last_index + 1);
        end
    end;

    on_color_mode_update = function(data)
        if nil == data or nil == data.color_mode then
            return;
        end
        base_utility.log("[banner_control]on_color_mode_update: " .. tostring(data.color_mode), true);
        local color_mode = data.color_mode;
        
        banner_control.color_text_ = "COLOR:RGB:48,48,51;";
        if color_mode == MainCommon.color_mode.kLight then
            banner_control.color_text_ = "COLOR:RGB:71,71,75;";
        end;
        if banner_view.more_menu_btn_id_ == nil then
            return;
        end;
        ui_utility.setproperty_by_id(banner_view.more_menu_btn_id_, "BackgroundHover",
                banner_control.color_text_);
    end;
};

banner_control.init();